import matplotlib.pyplot as plt
import numpy as np
import os

def cr():
    x_data = ['MID', 'EDF', 'INS', 'SRPT', 'FB', 'THR', 'OPTFB', 'RM', 'SEDF', 'SALL', 'FIFO', 'FEDF']
    cr_data = [0.7955186539989486, 0.9721756112288037, 0.9750584984719075, 0.8441982216268523, 0.9702974472045391, 0.9702974472045391, 0.9726939707920249, 0.9554093853954092, 0.9715420987627035, 0.8595374711592848, 0.44886601552629296, 0.4540814811272056]
    plt.bar(x_data,cr_data,color="deepskyblue",label="Average Completion Rate")

    #line
    ave_us_data = [0.7431623999999999, 0.8624654000000003, 0.8771357999999999, 0.7771982000000002, 0.8676079999999999, 0.8676079999999999, 0.8751396000000001, 0.8646974000000001, 0.8755368000000001, 0.7882542000000002, 0.45572219999999986, 0.45896080000000006]
    worst_us_data = [0.73218, 0.86071, 0.8748, 0.7711, 0.86581, 0.86581, 0.87317, 0.86319, 0.87331, 0.78191, 0.45269, 0.45509]
    ave_Comp_ratio = [0.8289504857726071, 0.9620254096440642, 0.9783893096563339, 0.8669152602871134, 0.9677616535231063, 0.9677616535231063, 0.9761626752629639, 0.9645150639702844, 0.9766057266511248, 0.8792475265195031, 0.5083291876275781, 0.5119416403609552]
    worst_Comp_ratio = [0.8167003156685368, 0.9600673723661755, 0.9757838730187058, 0.860113105263745, 0.9657560986492064, 0.9657560986492064, 0.9739657114811882, 0.962833654950865, 0.97412187259484, 0.8721709741107182, 0.5049469609931847, 0.5076240086557875]
    plt.plot(x_data, ave_us_data, color = "sandybrown", marker='o', ms=3, label="ave_us")
    plt.plot(x_data, worst_us_data, color = "crimson", marker='o', ms=3, label="worst_us")
    plt.plot(x_data, ave_Comp_ratio, color = "plum", marker='o', ms=3, label="ave_compratio")
    plt.plot(x_data, worst_Comp_ratio, color = "indigo", marker='o', ms=3, label="worst_compratio")
    plt.legend()
    plt.title('Completion rate & US & CompRatio')
    graph_path = os.path.dirname(os.path.abspath(__file__)) + '/graph/'
    if not os.path.isdir(graph_path):
        os.makedirs(graph_path)
    file_name = graph_path + __file__.split('/')[-1].split('.')[0]
    plt.savefig(f"{file_name}.pdf", bbox_inches='tight')
    plt.close()


if __name__ == '__main__':
    cr()
        
